﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Modbus.Utility;

namespace ModbusTestTool
{
    class FloatType:BaseRegisterGeneric<float>
    {
        /// <summary>
        /// The actual internal value
        /// </summary>
        


        public FloatType(string inParamName, int inRegister)
            : base(inParamName, inRegister)
        {
        }

        public override int size
        {
            get { return 2; }
        }
        


        /// <summary>
        /// Pass in an array which represent a modbus range exampe 40000-49999 the function will extract value from array
        /// </summary>
        /// <param name="dataStore">An array representing modbus array</param>
        public override void setValue(ushort[] dataStore)
        {
            lock (lockVariable)
            {
                
                m_result = ModbusUtility.GetSingle(dataStore[baseRegister+1], dataStore[baseRegister]);
                NotifyPropertyChanged("value");
            }
            
        }


        public override void getValue(ushort[] words)
        {
            lock (lockVariable)
            {
                byte[] all = BitConverter.GetBytes(m_result);

                //if t1 or t2 is slected this needs to be flipped
                words[baseRegister+1] = BitConverter.ToUInt16(all, 2);
                words[baseRegister] = BitConverter.ToUInt16(all, 0);

                NotifyPropertyChanged("value");
            }
        }



    }
}
